home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98c.txt
/
000077_icon-group-sender _Fri Nov 13 16:45:35 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
4KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) with SMTP id QAA04592
for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Fri, 13 Nov 1998 16:45:31 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA07516; Fri, 13 Nov 1998 16:45:30 -0700
Message-Id: <4FD6422BE942D111908D00805F3158DF0757B73A@RED-MSG-52>
From: Todd Proebsting <toddpro@microsoft.com>
To: "'Mark Laster'" <mlaster@smart.net>, icon-group@optima.CS.Arizona.EDU
Subject: RE: Coding multi-part patterns, as in SNOBOL
Date: Fri, 13 Nov 1998 12:59:48 -0800
X-Mailer: Internet Mail Service (5.5.2232.9)
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
I believe the following "strip()" routine will do what you want. (It is
possible to write it more concisely, but at the expense of clarity.) The
"main()" routine simply provides a driver routine that reads lines, strips
them and prints the results.
Todd Proebsting
procedure main()
while write(strip(read()))
end
procedure strip(s)
s ? { # scan
string
tab(many(' ')) # tab past spaces
if tab(many('>')) then { # tab past >'s
return tab(0) # return remainder
} else {
return s # no >'s, so return
s
}
}
end
-----Original Message-----
From: Mark Laster [mailto:mlaster@smart.net]
Sent: Friday, November 13, 1998 9:09 AM
To: icon-group@optima.CS.Arizona.EDU
Subject: Coding multi-part patterns, as in SNOBOL
Subject: Coding multi-part patterns, as in SNOBOL
Friday, 11/13/98
Hello,
After years of programming in SNOBOL, I've been learning ICON,
but some operations in ICON require me (because I don't know a
neater way) to write far more lines of code than would be
necessary in SNOBOL.
One of my programs in ICON processes e-mail messages. It does
more than the snippet shown here, but for purposes of
discussion, it removes the "e-mail quotation" marks from lines of
text. As you know, those marks in aggregate may be either:
(1) one or more angle brackets, starting at the left margin, or
(2) one or more spaces, starting at the left margin, FOLLOWED
IMMEDIATELY BY one or more angle brackets.
To remove these "e-mail quote" marks, I needed about 20 lines,
as shown below.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure main ( )
...
# have gotten a line of text, called "rec" here, by now
repeat {
if /rec then {
rec := " "
break
}
else
if locnb := many('>', rec) then
rec := rec[locnb:0]
if dbg1 := (many(' ', rec)) then {
if dbg2 := (many('>', rec[dbg1])) then
rec := rec[dbg1+dbg2-1:0]
else # found starting blanks but no ">" immediately after
break
} # end of "if dbg1 := (many(' ' ..."
else # rec line does not start with blank or ">"
break
} # repeat for each workline
# write the record out
...
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To perform the same operation in SNOBOL requires two lines (if
that many):
...
qupat = pos(0) (span(" ") | null) span(">") rem . rec
...
strip rec qupat :s(strip)
...
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I've read through the file PATTERNS.ICN, written in 1988, and I
know how to $include it, but I don't know how to use it. I'd
be glad to lose some run-time efficiency in order to gain some
coding-time efficiency.
Assuming that there is a way to code the quote-stripping
operation in ICON more efficiently than I have, optionally
using the PATTERNS.ICN file or superseding files, could you
show me how to do it in ICON, so I can see how to combine
multiple conditions in a match:
(1) starting at the left margin
(2) optionally encountering one or more blanks
(3) encountering one or more ">" directly afterward.
That would help me learn how to code a variety of complex
conditions.
Thank you very much.
Sincerely yours,
Mark Laster (301) 805-4462 mlaster@smart.net
15775 Easthaven Court
Bowie, MD 20716-2620